using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace DTO
{
	/// <summary> 
	///Author: nnamthach@gmail.com 
	/// <summary>
	
    public class MaterialDetailInfo
    {
		#region Local Variable
		public enum Field
		{
			DTB,
			RequestNo,
			DetailNo,
			ItemCode,
			Description,
			ModelPN,
			Unit,
			Qty,
			BudgetCode,
			GLAccount,
			Remark
		}
		private String _DTB;
		private String _RequestNo;
		private Int32 _DetailNo;
		private String _ItemCode;
		private String _Description;
		private String _ModelPN;
		private String _Unit;
		private Double _Qty;
		private String _BudgetCode;
		private String _GLAccount;
		private String _Remark;
		
		public String DTB{	get{ return _DTB;} set{_DTB = value;} }
		public String RequestNo{	get{ return _RequestNo;} set{_RequestNo = value;} }
		public Int32 DetailNo{	get{ return _DetailNo;} set{_DetailNo = value;} }
		public String ItemCode{	get{ return _ItemCode;} set{_ItemCode = value;} }
		public String Description{	get{ return _Description;} set{_Description = value;} }
		public String ModelPN{	get{ return _ModelPN;} set{_ModelPN = value;} }
		public String Unit{	get{ return _Unit;} set{_Unit = value;} }
		public Double Qty{	get{ return _Qty;} set{_Qty = value;} }
		public String BudgetCode{	get{ return _BudgetCode;} set{_BudgetCode = value;} }
		public String GLAccount{	get{ return _GLAccount;} set{_GLAccount = value;} }
		public String Remark{	get{ return _Remark;} set{_Remark = value;} }
		
        #endregion LocalVariable
        
        #region Constructor
		public MaterialDetailInfo()
		{
			_DTB = "";
			_RequestNo = "";
			_DetailNo = 0;
			_ItemCode = "";
			_Description = "";
			_ModelPN = "";
			_Unit = "";
			_Qty = 0;
			_BudgetCode = "";
			_GLAccount = "";
			_Remark = "";
		}
		public MaterialDetailInfo(
		String DTB,
		String RequestNo,
		Int32 DetailNo,
		String ItemCode,
		String Description,
		String ModelPN,
		String Unit,
		Double Qty,
		String BudgetCode,
		String GLAccount,
		String Remark
		)
		{
			_DTB = DTB;
			_RequestNo = RequestNo;
			_DetailNo = DetailNo;
			_ItemCode = ItemCode;
			_Description = Description;
			_ModelPN = ModelPN;
			_Unit = Unit;
			_Qty = Qty;
			_BudgetCode = BudgetCode;
			_GLAccount = GLAccount;
			_Remark = Remark;
		}
		public MaterialDetailInfo(DataRow dr)
		{
			if (dr != null)
			{
				_DTB = dr[Field.DTB.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.DTB.ToString()]);
				_RequestNo = dr[Field.RequestNo.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.RequestNo.ToString()]);
				_DetailNo = dr[Field.DetailNo.ToString()] == DBNull.Value?0:Convert.ToInt32(dr[Field.DetailNo.ToString()]);
				_ItemCode = dr[Field.ItemCode.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.ItemCode.ToString()]);
				_Description = dr[Field.Description.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Description.ToString()]);
				_ModelPN = dr[Field.ModelPN.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.ModelPN.ToString()]);
				_Unit = dr[Field.Unit.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Unit.ToString()]);
				_Qty = dr[Field.Qty.ToString()] == DBNull.Value?0:Convert.ToDouble(dr[Field.Qty.ToString()]);
				_BudgetCode = dr[Field.BudgetCode.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.BudgetCode.ToString()]);
				_GLAccount = dr[Field.GLAccount.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.GLAccount.ToString()]);
				_Remark = dr[Field.Remark.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Remark.ToString()]);
			}
		}
		public MaterialDetailInfo(DataRowView dr)
		{
			if (dr != null)
			{
				_DTB = dr[Field.DTB.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.DTB.ToString()]);
				_RequestNo = dr[Field.RequestNo.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.RequestNo.ToString()]);
				_DetailNo = dr[Field.DetailNo.ToString()] == DBNull.Value?0:Convert.ToInt32(dr[Field.DetailNo.ToString()]);
				_ItemCode = dr[Field.ItemCode.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.ItemCode.ToString()]);
				_Description = dr[Field.Description.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Description.ToString()]);
				_ModelPN = dr[Field.ModelPN.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.ModelPN.ToString()]);
				_Unit = dr[Field.Unit.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Unit.ToString()]);
				_Qty = dr[Field.Qty.ToString()] == DBNull.Value?0:Convert.ToDouble(dr[Field.Qty.ToString()]);
				_BudgetCode = dr[Field.BudgetCode.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.BudgetCode.ToString()]);
				_GLAccount = dr[Field.GLAccount.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.GLAccount.ToString()]);
				_Remark = dr[Field.Remark.ToString()] == DBNull.Value?"":Convert.ToString(dr[Field.Remark.ToString()]);
			}
		}
		public MaterialDetailInfo(MaterialDetailInfo objEntr)
		{			
			_DTB = objEntr.DTB;			
			_RequestNo = objEntr.RequestNo;			
			_DetailNo = objEntr.DetailNo;			
			_ItemCode = objEntr.ItemCode;			
			_Description = objEntr.Description;			
			_ModelPN = objEntr.ModelPN;			
			_Unit = objEntr.Unit;			
			_Qty = objEntr.Qty;			
			_BudgetCode = objEntr.BudgetCode;			
			_GLAccount = objEntr.GLAccount;			
			_Remark = objEntr.Remark;			
		}
        #endregion Constructor
        
        #region InitTable
		public static DataTable ToDataTable()
		{
			DataTable dt = new DataTable("MaterialDetail");
			dt.Columns.AddRange(new DataColumn[] { 
				new DataColumn(Field.DTB.ToString(), typeof(String)),
				new DataColumn(Field.RequestNo.ToString(), typeof(String)),
				new DataColumn(Field.DetailNo.ToString(), typeof(Int32)),
				new DataColumn(Field.ItemCode.ToString(), typeof(String)),
				new DataColumn(Field.Description.ToString(), typeof(String)),
				new DataColumn(Field.ModelPN.ToString(), typeof(String)),
				new DataColumn(Field.Unit.ToString(), typeof(String)),
				new DataColumn(Field.Qty.ToString(), typeof(Double)),
				new DataColumn(Field.BudgetCode.ToString(), typeof(String)),
				new DataColumn(Field.GLAccount.ToString(), typeof(String)),
				new DataColumn(Field.Remark.ToString(), typeof(String))
			});
			return dt;
		}
		public DataRow ToDataRow(DataTable dt)
		{
			DataRow row = dt.NewRow();
			row[Field.DTB.ToString()] = _DTB;
			row[Field.RequestNo.ToString()] = _RequestNo;
			row[Field.DetailNo.ToString()] = _DetailNo;
			row[Field.ItemCode.ToString()] = _ItemCode;
			row[Field.Description.ToString()] = _Description;
			row[Field.ModelPN.ToString()] = _ModelPN;
			row[Field.Unit.ToString()] = _Unit;
			row[Field.Qty.ToString()] = _Qty;
			row[Field.BudgetCode.ToString()] = _BudgetCode;
			row[Field.GLAccount.ToString()] = _GLAccount;
			row[Field.Remark.ToString()] = _Remark;
			return row;
		}
        #endregion InitTable
    }
}
